/**
 * Created by seeker910 on 2018/5/8.
 */
Rsd.define('Rsd.Faith.dialogs.FiscalDTJiaoCunDialog', {
    extend: 'Rsd.view.MajorSubDialog',
    requires: ['Rsd.controlEx.ModelViewer','Rsd.controlEx.ComboBoxEnum'],
    xtype:'dtjiaocun-dialog',
    width:1100,
    height:800,
    title:'电梯、消防设备专项资金缴存',
    major:{
        legend:'',
        header:{content:'&nbsp发票信息',position:'top',height:40,align:'left',width:'100%'},
        height:130,
        readOnly:false,
        fields:[
            {label:{content:'发票号',width:100},width:350,dataIndex:'fapiaohaoma',tabIndex:0},
            {label:{content:'开票内容',width:100},width:350,value:'电梯、消防设备专项维修基金',tabIndex:1},
            {label:{content:'发票金额',width:100},width:350,tabIndex:2},
            {label:{content:'开票人',width:100},width:350,tabIndex:3},
            {label:{content:'开票日期',width:100},width:350,tabIndex:4},
            {xtype:'combobox-enum',enum:'ShouFei_BiaoZhun_DT',label:{content:'缴费标准',width:100},width:350,tabIndex:5}
        ]
    },
    sub:{
        toolBar:{
            xtype:'grid-tool-bar-simple',
            newButtons:[
                {text:'  新 增 ✎',visible:true,handler:'btn_new'},
                {xtype:'label',text:'★ 下方列表为该发票缴存的楼栋所包含所有单元明细信息，【确定缴存】前请核实单元信息有无遗漏。👇'}
                ]},
        fk:'fph',
        height:200,
        columns:[
            {xtype:'index',text:'序号',fixWidth:50},
            {text:'小区',name:'xiaoQu',fixWidth: 100},
            {text:'栋号',width: 50,editable:true},
            {text:'层高',width: 50,editable:true},
            {text:'性质',width: 50,editable:true},
            {text:'缴费标准',width: 50,editable:true},
            {text:'单元',width: 50,editable:true},
            {text:'建筑面积',width: 60,editable:true},
            {text:'应缴金额',fixWidth: 70},
            {
                name: 'edit',
                width: 70,
                text: '操 作',
                nobr:true,
                xtype: 'template',
                format:'templateFormat'
            },
            {
                name: 'space',
                text: '',
                xtype: 'template',
                width: 5,
                hideable: false,
                sortable: false
            }
        ]
    },
    footer:{
        height:80,style:{fontSize:'120%',left:'50px'},
        items:[
            {
                xtype:'button',height:40,width:500,text:'Ⓢ确 定 缴 存',handler:'btn_ok',
                label:{content:'请核实【应缴金额合计】与【发票金额】是否一致。',position:'right',width:350}
            }
            ]
    },
    /*
     *
     * */
    constructor: function constructor(config) {
        config = config || {};
        this.apply(config);

    },
    load:function load(data) {

        var _data = this.data = data;
        this.callParent({},[
            {___isEdit:true,xiaoQu:_data.MingCheng},
            {___isEdit:true,xiaoQu:_data.MingCheng},
            {___isEdit:true,xiaoQu:_data.MingCheng},
            {___isEdit:true,xiaoQu:_data.MingCheng}
            ]);

    },
    btn_ok:function btn_ok() {
        Rsd.popup('缴存成功');
        this.close();
    },
    /*
    *
    * */
    templateFormat:function templateFormat(row,evt) {
        var me = this;
        var  btnUpdate = document.createElement('a');
        btnUpdate.href='#';
        btnUpdate.style.display = row.___isEdit ? 'none' :'';
        btnUpdate.innerHTML = '修改✍';

        var btnSave = document.createElement('a');
        btnSave.href='#';
        btnSave.style.display = row.___isEdit ? '' :'none';
        btnSave.innerHTML = '保存✓';

        var btnCancel = document.createElement('a');
        btnCancel.href='#';
        btnCancel.style.display = row.___isEdit ? '' :'none';
        btnCancel.innerHTML = '取消↩';

        var  btnDel = document.createElement('a');
        btnDel.href='#';
        btnDel.style.display = row.___isEdit ? 'none' :'';
        btnDel.innerHTML = '删除✗';

        if(row.___isEdit)
        {
            setTimeout(function () {
                evt.parent.editRow(evt.rowIndex,row.___isEdit);
            },10);
        }
        $(btnUpdate).click (function(){
            row.___isEdit = true;
            evt.parent.editRow(evt.rowIndex,row.___isEdit);

            btnSave.style.display = '';
            btnCancel.style.display = '';
            btnUpdate.style.display = 'none';
            btnDel.style.display = 'none';
        } );


        $(btnDel).click (function(){
            Rsd.yesOrNo('【重要提醒】您确定要删除该数据？',function () {
                evt.parent.deleteRow(evt.rowIndex);
                Rsd.popup('删除成功(模拟) RowINdex:' +  evt.rowIndex);

            });
        } );

        $(btnSave).click (function(){
            var _newRow =  evt.parent.getRowData(evt.rowIndex);
            //保存数据

            evt.parent.updateRow(evt.rowIndex,_newRow);

            Rsd.popup('修改成功 RowINdex:' +  evt.rowIndex);

            btnSave.style.display = 'none';
            btnCancel.style.display = 'none';
            btnUpdate.style.display = '';
            btnDel.style.display = '';
        } );

        $(btnCancel).click (function(){
            row.___isEdit = false;
            evt.parent.editRow(evt.rowIndex,row.___isEdit);

            btnSave.style.display = 'none';
            btnCancel.style.display = 'none';
            btnUpdate.style.display = '';
            btnDel.style.display = '';
        } );

        return [btnUpdate,btnSave,Rsd.blankspan(),btnDel,btnCancel] ;
    },
    /*
    * */
    btn_new:function btn_new(obj ,evt) {
        var _data = this.data ||{};
        var _table = obj.parent.parent.parent;
        //新增 行
        _table.newRow({___isEdit:true,xiaoQu:_data.MingCheng},true);
    }
});